from selenium import webdriver
import time

username = "username"
password = "password"


# https://shfwyy.cauc.edu.cn/badminton/save.do?token=6a365fc1253535aa34c812312379189999


while True:
    now = time.localtime()
    current_time = time.strftime("%H:%M", now)
    print(current_time)

    if current_time == "06:58" or True:
        chrome_driver_path = "D:\chromedriver\chromedriver.exe"
        driver = webdriver.Chrome(chrome_driver_path)
        driver.get("https://shfwyy.cauc.edu.cn/")
        # 使用CSS选择器找到具有多个类名的元素，并输入相应的值
        driver.find_element_by_css_selector(".van-field__control[name='用户名']").send_keys(username)
        driver.find_element_by_css_selector(".van-field__control[name='密码']").send_keys(password)
        # 使用CSS选择器找到登录按钮的元素，并单击它
        driver.find_element_by_css_selector(
            ".van-button--info.van-button--normal.van-button--block.van-button--round").click()

        # 选择预约体育馆页面
        time.sleep(1)  # 等待1秒以确保登录成功
        life_service_tab = driver.find_element_by_xpath("//div[@class='van-tabbar-item__text' and text()='生活服务']")
        life_service_tab.click()

        # 使用XPath表达式定位羽毛球场地元素，并单击它
        time.sleep(1)
        badminton_field = driver.find_element_by_xpath("//span[@data-v-425b8292 and text()='羽毛球场地']")
        badminton_field.click()

        element = driver.find_element_by_xpath('//span[@data-v-7be49268=""]')
        element.click()

        time.sleep(0.5)
        element = driver.find_element_by_xpath(
            '//*[@id="app"]/div/div[1]/div[9]/div/div[2]/div[2]/div/div[1]/div/ul/li[1]/span')
        element.click()

        time.sleep(0.5)
        element = driver.find_element_by_xpath(
            '//*[@id="app"]/div/div[1]/div[9]/div/div[2]/div[2]/div/div[2]/div/ul/li[7]/span')
        element.click()

        time.sleep(1)
        element = driver.find_element_by_xpath('//*[@id="list-content-hair"]/div/div/div[3]/div[3]/div/i')
        element.click()

        time.sleep(0.5)
        element = driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/div[7]/div/button')
        element.click()

        time.sleep(0.5)
        driver.find_element_by_class_name('van-dialog__confirm').click()

        break
    else:
        print('等待,现在是' + current_time)
        time.sleep(60)

# 关闭浏览器
# driver.quit()
